package org.wlgzs.com.config;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import javax.sql.DataSource;
/**
 * @ProjectName: internet_campus
 * @Package: org.wlgzs.com.config
 * @ClassName: DataSourceConfig
 * @Description: java类作用描述:配置数据源，减少连接数据库的次数。
 * @Author: alj
 * @CreateDate: 2019/1/21 4:58
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/1/21 4:58
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
@Configuration
public class DataSourceConfig {

    @Bean(name="dataSource")
    @ConfigurationProperties(prefix="spring.datasource")
    public DataSource dataSource(){
        return new DruidDataSource();
    }

    /**
     *配置事物管理器
     */
    @Bean(name="transactionManager")
    public DataSourceTransactionManager transactionManager(){
        return new DataSourceTransactionManager(dataSource());
    }
}
